import {defineStore} from 'pinia'

interface State {
    count: number
}

export interface CounterStore extends State {
    getDouble: number,
    increment: () => void,
    randomize: () => void,
    reset: () => void,
    dispose: () => void
}

export const useCounter = defineStore('counter', {
    state: (): State => ({
        count: 0
    }),
    getters: {
        getDouble: (state) => state.count * 2
    },
    actions: {
        increment() {
            this.count++
        },
        randomize() {
            this.count = Math.round(100 * Math.random())
        },
        reset() {
            this.$reset()
        },
        dispose() {
            this.$dispose()
        }
    }
})
